package com.monitor.service.impl;

import java.io.File;

import org.apache.struts2.ServletActionContext;

import com.monitor.dao.EnvironmentRecordDao;
import com.monitor.po.EnvironmentRecord;
import com.monitor.service.EnvironmentRecordService;
import com.monitor.util.FileUtil;
import com.monitor.util.Pager;

public class EnvironmentRecordServiceImpl implements EnvironmentRecordService {
	private EnvironmentRecordDao environmentRecordDao;

	@Override
	public Pager<EnvironmentRecord> getEnvironmentRecordByUid(long uid, int pageSize, int currentPage) throws Exception {
		return environmentRecordDao.getEnvironmentRecordByUid(uid, pageSize, currentPage);
	}

	@Override
	public boolean deleteEnvironmentRecord(long uid, long id) throws Exception {
		EnvironmentRecord record = environmentRecordDao.getEnvironmentRecordById(id);
		if (record != null && uid == record.getOwnerUid()) {
			environmentRecordDao.deleteEnvironmentRecord(record);
			String filePath = ServletActionContext.getServletContext().getRealPath("") + File.separator + record.getPath();
			// 删除用户文件目录
			FileUtil.deleteFile(new File(filePath));
			return true;
		} else {
			return false;
		}
	}

	public EnvironmentRecordDao getEnvironmentRecordDao() {
		return environmentRecordDao;
	}

	public void setEnvironmentRecordDao(EnvironmentRecordDao environmentRecordDao) {
		this.environmentRecordDao = environmentRecordDao;
	}

}
